#ifndef THREADBASE_H
#define THREADBASE_H

/***********************************************
* [className]   QTcpThreadBase
* [func]        线程基类（由老版本移植，做了接口扩充）
* [author]      jhb
* [date]        2024-05-06
* [Modification Log]
* Version               By              Notes
* V0.0.1                jhb             初次创建
************************************************/

#include <QObject>
#include <QThread>
#include <QTimer>

//最小线程循环时间，单位ms
const int g_nMinCirculateTime = 50;

class QTcpThreadBase : public QObject
{
    Q_OBJECT
public:
    QTcpThreadBase(QObject *parent = nullptr);
    ~QTcpThreadBase();
    //线程是否关闭
    bool isStop();

public slots:
    //开始线程|nWaitTime>0时 代表需要延时启动线程
    void startWorkThread(int nWaitTime = 0);
    //停止线程
    void stopWorkThread();

signals:
    //启动工作线程信号
    void sigStartWorkProc();

protected slots:
    //工作线程
    virtual void slotWorkProc() = 0;

protected:
    QThread m_thread;
    bool m_bStopWorkThread;//停止线程标志

protected:
    //线程循环  nWaitTime|下次线程循环到来的时间，单位：毫秒(暂时未使用)
    void threadCirculate(int nWaitTime);
    //线程休眠，nWaitTime:ms
    void threadSleep(int nWaitTime);
    //线程开启通知
    virtual void threadStart();
    //线程结束通知
    virtual void threadStop();
};

#endif // THREADBASE_H
